package com.l.web.action;

import com.l.web.service.KeyUpdate;
import com.l.web.service.ResponseCode;
import com.l.web.service.ResponseInfo;
import com.l.web.service.ServiceSupport;
import com.l.web.service.system.user.User;
import com.l.web.service.system.user.UserDAO;
import org.apache.log4j.Logger;

public class MyinfoSave extends ServiceSupport {

    private static final Logger LOGGER = Logger.getLogger(MyinfoSave.class);

    private UserDAO userDAO;

    public void setUserDao(UserDAO userDAO) {
        this.userDAO = userDAO;
    }

    public String execute() {
        KeyUpdate keyUpdate = new KeyUpdate(User.class);
        boolean result = form.getBean(keyUpdate);
        LOGGER.debug("修改信息：" + keyUpdate);
        if (result && keyUpdate.check()) {
            int code = ResponseCode.FINISH;
            try {
                userDAO.update(keyUpdate);
            } catch (Exception e) {
                code = ResponseCode.FAILURE;
                LOGGER.error("修改异常[" + keyUpdate + "]：" + e);
            }
            ResponseInfo msg = new ResponseInfo(code);
            out(msg);
        } else {
            LOGGER.error("非法修改：" + keyUpdate);
            error(404);
        }
        return NONE;
    }

}
